/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package a1A;

/**
 *
 * @author nisarg
 */
public class water_shield1 {
    
    static int val1 = 0,row = 3,col = 3;
    /*static int input[][] = {{1,2,3,4,5},{2,9,3,9,6},{3,3,0,8,7},{4,9,8,9,8},{5,6,7,8,9}};
    static int input1[][] = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
    static int input2[][] = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};*/
    static int input[][] = {{9,6,3},{5,9,6},{3,5,9}};
    /*static int input[][] = {{1,2,3},{4,5,6},{7,8,9}};*/
    static int input1[][] = {{0,0,0},{0,0,0},{0,0,0}};
    static int input2[][] = {{0,0,0},{0,0,0},{0,0,0}};
    /*static int input[][] = {{8,8,8,8,8,8,8,8,8,8,8,8,8},{8,8,8,8,8,8,8,8,8,8,8,8,8}};
    static int input1[][] = {{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0}};
    static int input2[][] = {{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0}};*/
    public static void main(String args[]) {
        //water_shield1 w = new water_shield1();
        int max = input[0][0],min = input[0][0];
        int i1 = 0,j1 = 0,count = 0;
        for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                if(min > input[i][j]) {
                    min= input[i][j];
                }
            }
        }
        
        for(int t=0;t<row*col;t++) {
            max = min - 1;
            for(int i=0;i<row;i++) {
                for(int j=0;j<col;j++) {
                    if(max < input[i][j] && input2[i][j] == 0) {
                        max = input[i][j];
                        i1 = i;
                        j1 = j;
                    }
                }
            }
            //System.out.println("max" + (t+1) + " = " + max + " i = " + i1 + " j = " + j1);
            input2[i1][j1] = 1;
            min(i1,j1);
        }
        for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                System.out.print((char)(input1[i][j] + 96) + " ");
            }
            System.out.println();
        }
        /*System.out.println();
        System.out.println();
        System.out.println();*/
        /*for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                System.out.print(input2[i][j]);
            }
            System.out.println();
        }*/

    }
    static void min(int i,int j) {
        //water_shield1 w = new water_shield1();
        /*int max = input[0][0];
        for(int m=0;m<row;m++) {
            for(int n=0;n<col;n++) {
                if(max < input[m][n] && input1[m][n] != 0) {
                    max = 
                }
            }
        }*/
        int a=0,b=0;
        //int min = w.input[i][j];
        int min_ard = 1000;
        
        if((j-1)>=0) {
            min_ard = input[i][j-1];
            a = i;
            b = j-1;
        }
        if((i-1)>=0 && min_ard > input[i-1][j]) {
            min_ard = input[i-1][j];
            a = i-1;
            b = j;
        }
        if((i+1)<row && min_ard > input[i+1][j]) {
            min_ard = input[i+1][j];
            a = i+1;
            b = j;
        }
        if((j+1)<row && min_ard > input[i][j+1]) {
            min_ard = input[i][j+1];
            a = i;
            b = j+1;
        }
        //System.out.println("a = " + a + " b = " + b);
        //System.out.println("input1[a][b]" + input1[a][b] + " input1[i][j] = " + input1[i][j]);
        if(input1[a][b] == 0) {
            if(input1[i][j] != 0) {
                input1[a][b] = input1[i][j];
                //System.out.println("assign...");
                //replace(input1[a][b], input1[i][j]);
            }
            else {
            input1[a][b] = input1[i][j] = ++val1;
            //System.out.println("val1" + val1 + " i=" + i + " j = " + j + " a = " + a + " b = " + b);
            }
        }
        else if(input[a][b] != input[i][j]) {
            //System.out.println("input[i][j] = " + input1[i][j] + "input[a][b] = " + input1[a][b]);
            int temp = input1[i][j];
            input1[i][j] = input1[a][b];
            if(input1[a][b] < temp) replace(temp, input1[a][b]);
            else replace(input1[a][b],temp);
            //System.out.println("replace");
        }
        else {
            input1[i][j] = ++val1;
            //System.out.println("");
        } 
    }
    static void replace(int a,int b) { //a is original value, to be replaced with b.
        for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                //System.out.println("a = " + a + " b = "+ b + " input1 = " +input1[i][j]);
                if(input1[i][j] == a && input1[i][j] != 0) {
                    input1[i][j] = b;
                    //System.out.println("in replace a = " + a + " b = " + b + "  i = " + i + " j = " + j);
                }
                //else
                    //System.out.println("input[i][j] = " + input1[i][j]);
            }
        }
        //System.out.println("AFTER");
        /*for(int i=0;i<row;i++) {
            for(int j=0;j<col;j++) {
                System.out.print(input1[i][j]);
            }
            System.out.println();
        }*/
    }
}